import {Component} from '@angular/core';
import {IonicModule} from '@ionic/angular';
import { FormsModule } from '@angular/forms';
import { TextToSpeech } from '@ionic-native/text-to-speech/ngx';
import { NgIf } from '@angular/common';
import { Platform } from '@ionic/angular';


@Component({
  selector: 'tts',
  templateUrl: 'tts.page.html',
  styleUrls: ['tts.scss'],
  standalone: true,
  imports: [IonicModule,FormsModule,NgIf],
})
export class TTSPage {
  inputText: string;
  speedRate = 1;
  locale = 'en-US'; 
  progress = 0;
  errorMessage: string;

  constructor(private platform: Platform,private tts: TextToSpeech) { 
    this.inputText=""
    this.errorMessage=""
  }

  ngOnInit() {
    
  }
  speak() {
    this.platform.ready().then(() => {
      this.tts.speak({
      text: this.inputText,
      rate: this.speedRate,
      locale: this.locale,
    }).then(() => console.log('Speech success')).catch(error => console.log(`Speech error: ${error}`));
    });
   
  }

  stop() {
    this.tts.stop().then(() => console.log('Speech stopped'));
  }
}
